package com.example.win.android_banduyujia.venuesactivity.activity.classactivity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.example.win.android_banduyujia.R;
import com.example.win.android_banduyujia.lib.util.StrUtils;
import com.example.win.android_banduyujia.peopleactivity.ui.activity.BaseTitleBarActivity;

/**
 * Created by Win on 2015/9/12.
 */
public class NameActivity extends BaseTitleBarActivity {

    private EditText    mEditClassesName;
    private ImageView   mImageViewDelete;
    private String      mClassesName = " ";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_classes_name_page);

        InitTitles();
        InitViews();
    }

    private void InitTitles() {
        showLeftBackButton();
        setTitle(R.string.layout_text_view_classes_name);
        setRightTextViewListener(R.string.layout_data_save_button, mRightListener);
    }

    private View.OnClickListener mRightListener = new View.OnClickListener(){

        @Override
        public void onClick(View v) {
            if(StrUtils.isEmpty(mClassesName)){
                showToast(R.string.layout_data_save_button);
                return;
            }
            saveNickName();
        }
    };

    private void saveNickName() {

    }

    private void InitViews() {
        mEditClassesName = (EditText)findViewById(R.id.classes_name_edit_text);
        mImageViewDelete = (ImageView)findViewById(R.id.classes_name_image_icon );
        mImageViewDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mEditClassesName.setText(" ");
            }
        });
        mEditClassesName.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                mClassesName = s.toString();
                if (StrUtils.isEmpty(mClassesName)) {
                    mImageViewDelete.setVisibility(View.GONE);
                } else {
                    mImageViewDelete.setVisibility(View.VISIBLE);
                }
            }
        });
    }
}
